package cn.lili.modules.grab.factory.order;

import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.grab.GrabOrderParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
@RequiredArgsConstructor
public class GrabOrderFactory {

    private final List<GrabOrderService> orderServiceList;

    /**
     * 运费计算工厂
     *
     * @param grabParam 参数
     */
    public ResultMessage<Object> generateFreightCalcFactory(GrabOrderParam grabParam) {
        GrabOrderService grabOrderService = orderServiceList.stream().filter(service -> service.step().name().equals(grabParam.getCode())).findFirst().get();
        return grabOrderService.freightCalc(grabParam);
    }

    /**
     * 创建订单工厂
     *
     * @param grabParam 参数
     */
    public ResultMessage<Object> generateCreateOrderFactory(GrabOrderParam grabParam) {
        GrabOrderService grabOrderService = orderServiceList.stream().filter(service -> service.step().name().equals(grabParam.getCode())).findFirst().get();
        return grabOrderService.createOrder(grabParam);
    }

    /**
     * 订单详情
     *
     * @param grabParam 参数
     */
    public ResultMessage<Object> generateGetOrderInfoOrderFactory(GrabOrderParam grabParam) {
        GrabOrderService grabOrderService = orderServiceList.stream().filter(service -> service.step().name().equals(grabParam.getCode())).findFirst().get();
        return grabOrderService.getOrderInfo(grabParam);
    }
}
